package com.indusfo.spc.client.controller;

import com.indusfo.spc.annotation.UserLoginToken;
import com.indusfo.spc.aspect.SystemControllerLog;
import com.indusfo.spc.client.pojo.ClientAno;
import com.indusfo.spc.client.pojo.ClientAnoDetail;
import com.indusfo.spc.client.service.ClientAnoService;
import com.indusfo.spc.client.service.ClientBadphenoService;
import com.indusfo.spc.vo.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangq
 * @create 2019-12-20
 */
@RestController
@RequestMapping("/client/clientAno")
public class ClientAnoController {

	@Autowired
	private ClientAnoService clientAnoService;
	@Autowired
	private ClientBadphenoService clientBadphenoService;

	/**
	 * 查询
	 *
	 * @param clientAno
	 * @return com.indusfo.spc.vo.JSONObject
	 */
	@RequestMapping(value = "/queryClientAno")
	@SystemControllerLog(description = "查询")
	@ResponseBody
	public JSONObject queryClientAno(ClientAno clientAno) {
		JSONObject json = clientAnoService.selectClientAno(clientAno);
		return json;
	}

	/**
	 * 查询明细
	 *
	 * @param clientAnoDetail
	 * @return com.indusfo.spc.vo.JSONObject
	 */
	@RequestMapping(value = "/queryClientAnoDetail")
	@SystemControllerLog(description = "查询明细")
	@ResponseBody
	public JSONObject queryClientAnoDetail(ClientAnoDetail clientAnoDetail) {
		JSONObject json = clientAnoService.queryClientAnoDetail(clientAnoDetail);
		return json;
	}

	/**
	 * 根据批次ID和工位查询不良现象
	 * 
	 * @param ClientAno
	 * @return
	 */
	@PostMapping("/queryBadphenoByBatchId")
	@UserLoginToken
	public JSONObject queryBadphenoByBatchId(@RequestBody ClientAno clientAno) {
		try {
			return JSONObject
					.oK(clientBadphenoService.queryBadphenoByBatchId(clientAno.getBatchId(), clientAno.getStationId()));
		} catch (Exception e) {
			return JSONObject.build(JSONObject.ERROR, "系统错误，请联系管理员！");
		}
	}

	/**
	 * 不良保存
	 * 
	 * @param ClientAno
	 * @return
	 */
	@PostMapping("/insertClientAno")
	@UserLoginToken
	public JSONObject insertClientAno(@RequestBody ClientAno clientAno) {
		try {
			return JSONObject.oK(clientAnoService.insertClientAno(clientAno));
		} catch (Exception e) {
			return JSONObject.build(JSONObject.ERROR, e.getMessage());
		}

	}
}
